<?php
/*
Template Name: Search Page
 */
?>
<?php 
require( dirname(dirname( __FILE__ )) . '/wp-blog-header.php' );//Should we put this file under a subfolder such as 'wordpress_01\oursearch' ?
get_header(); ?>

<style media="screen" type="text/css">
.rsrc-search-form { 
margin: 0 auto; 
width:500px;
}

.rsrc-select
{
    -webkit-appearance: select;
        background: #e05d22; /* Old browsers */
        background: -webkit-linear-gradient(top, #e05d22 0%, #d94412 100%); /* Chrome 10+, Safari 5.1+ */
        background:   linear-gradient(to bottom, #e05d22 0%, #d94412 100%); /* W3C */
        border: none;
        border-bottom: 3px solid #b93207;
        border-radius: 2px;
        /*color: #b93207;*/
        display: inline-block;
        padding: 11px 10px 10px;
        text-decoration: none;
        width: 170px;
}

.rsrc-input
{
    width: 250px;
        border: 2px solid #b93207;
        height: 44px;
}
</style>

<form action="" method="POST" class="rsrc-search-form">
<table>
<br>
<tr>
<select id="searchDropDownBox" class="rsrc-select" name="searchCategory">
<option selected="selected" value="searchAll">All</option>
<option value="Book">Books</option>
<option value="Sermon">Sermons</option>
<option value="Bible Study Note">Bible Study Notes</option>
<option value="Web Reference">Web References</option>
</select>
<input type="text" name="f1" value="" class="rsrc-input"/>
<input type="submit" name="submit" value="Go"/>
</tr>
</table>
<br>
</form>
<?php 
if (isset($_POST['f1']))
{
        global $wpdb;    
        $queryStr = 'SELECT DISTINCT(title) FROM bhcbc_resource where title LIKE \'%'. $_POST['f1'] . '%\' OR DESCRIPTION LIKE \'%'. $_POST['f1'] . '%\'';    
        echo "<br>";
        $results = $wpdb->get_results($queryStr);  
        
        if(!empty($results)) { 
				$category = $_POST['searchCategory'];
				if ($wpdb->num_rows > 1) {
					$category = $category ."(s)";
				}
					
				echo " ". $wpdb->num_rows ." ". $category ." for ". $_POST['f1'] ." ";		
                
				foreach($results as $r) {        
                        echo "<p>".$r->title."</p>"; 
                }
				
        } else {
                echo "<p>No results found for \"". $_POST['f1'] ."\"!</p>";              
        } 
}
else
{
        //TODO
}
?>
<?php get_footer(); ?>
